package com.web.quartz.service.impl;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.quartz.Trigger;
import org.quartz.listeners.TriggerListenerSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.web.common.basic.quartz.entity.QuartzJobExecLog;

@Component
public class QuartzTriggerListener extends TriggerListenerSupport {
	
	@Autowired
	private QuartzJobExecLogServiceImpl quartzJobExecLogServiceImpl;


	@Override
	public String getName() {
		return "triggerListener-log";
	}

	@Override
	public void triggerMisfired(Trigger trigger) {
		QuartzJobExecLog log = new QuartzJobExecLog();
		log.setJobName(trigger.getJobKey().getName());
		log.setJobGroup(trigger.getJobKey().getGroup());
		log.setTriggerType(trigger.getClass().getSimpleName());
		log.setExecStartTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
		log.setExecEndTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
		log.setExecResult("等待超时，定时任务进行跳过");
		quartzJobExecLogServiceImpl.saveExecLog(log);
	}
}
